package com.e7.action;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.e7.common.Constants;
import com.e7.common.E7Action;
import com.e7.model.Activity;
import com.e7.model.Album;
import com.e7.model.Picture;
import com.e7.model.Vedio;
import com.e7.model.Video;
import com.e7.service.ActivityService;
import com.e7.service.PictureService;
import com.e7.service.VedioService;
import com.opensymphony.xwork2.Action;

@Component("activityAction")
public class ActivityAction extends E7Action {

	private static final long serialVersionUID = -2259410525163135044L;
	private ActivityService activityService;
	private VedioService vedioService;
	private PictureService picService;

	// client set
	private Integer id;
	private Integer num = 20;
	private Integer page = 1;
	private String order = Constants.OrderType.TIME;

	// return
	private List<Object> result;

	// private List<Activity> activities;
	// private List<Video> videoes;
	// private List<Picture> pictures;

	/**
	 * get the 20 most recent activities (global)
	 * 
	 * @return
	 */
	public String recentActivities() {
		List<Activity> activities = activityService.getOrderedActivities(num,
				Constants.OrderType.TIME);
		if (activities == null || activities.size() < 1) {
			this.code = Constants.ErrorCode.NOTEXIST;
			this.msg = "find no activity";
		}
		this.result = new ArrayList<Object>();
		this.result.addAll(activities);
		return Action.SUCCESS;
	}

	/**
	 * get the 20 most recommended activities (global)
	 * 
	 * @return
	 */
	public String recommendedActivities() {
		List<Activity> activities = activityService.getOrderedActivities(num,
				Constants.OrderType.RECOMMENDPOINT);
		if (activities == null || activities.size() < 1) {
			this.code = Constants.ErrorCode.NOTEXIST;
			this.msg = "find no activity";
		}
		this.result = new ArrayList<Object>();
		this.result.addAll(activities);
		return Action.SUCCESS;
	}
	
	public String allActivities() {
		List<Activity> activities = activityService.getAllActivities(order,
				this.page, this.num);
		if (activities == null || activities.size() < 1) {
			this.code = Constants.ErrorCode.NOTEXIST;
			this.msg = "find no activity";
		}
		this.result = new ArrayList<Object>();
		this.result.addAll(activities);
		return Action.SUCCESS;
	}
	
	public String activityInfo() {
		Activity activity = activityService.getActivity(this.id);
		if (activity == null) {
			this.code = Constants.ErrorCode.NOTEXIST;
			this.msg = "the specified activity does not exist";
		}
		this.result = new ArrayList<Object>();
		this.result.add(activity);
		return Action.SUCCESS;
	}

	public String picInfo() {
		Picture pic = this.picService.getPicture(this.id);
		// TODO
		this.result = new ArrayList<Object>();
		this.result.add(pic);
		return Action.SUCCESS;
	}

	public String vedioInfo() {
		Vedio video = this.vedioService.getVedio(this.id);
		// TODO
		this.result = new ArrayList<Object>();
		this.result.add(video);
		return Action.SUCCESS;
	}

	public String vedioes() {
		List<Video> videoes = this.vedioService.getVedioes(this.id, this.page,
				this.num);
		// TODO
		this.result = new ArrayList<Object>();
		this.result.add(videoes);
		return Action.SUCCESS;
	}

	public String pictures() {
		List<Picture> albums = this.picService.getPictures(this.id, this.page,
				this.num);
		// TODO
		this.result = new ArrayList<Object>();
		this.result.addAll(albums);
		return Action.SUCCESS;
	}

	public String albums() {
		List<Album> albums = this.picService.getAlbums(this.id, this.page,
				this.num);
		// TODO
		this.result = new ArrayList<Object>();
		this.result.addAll(albums);
		return Action.SUCCESS;
	}

	@Resource
	public void setActivityService(ActivityService activityService) {
		this.activityService = activityService;
	}

	@Resource
	public void setVedioService(VedioService vedioService) {
		this.vedioService = vedioService;
	}

	@Resource
	public void setPicService(PictureService picService) {
		this.picService = picService;
	}

	public List<Object> getResult() {
		return result;
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public void setNum(Integer num) {
		this.num = num;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public void setOrder(String order) {
		this.order = order;
	}
}
